from app import db
from app.models.activity import Activity


class ActivityService:
    @staticmethod
    def create_activity(data):
        if "type" not in data or "duration" not in data:
            raise ValueError("Missing required fields")

        activity = Activity(
            user_id=data.get("user_id"),
            type=data["type"],
            duration=data["duration"]
        )
        db.session.add(activity)
        db.session.commit()
        return activity